﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using Model.Interfaces;
using ViewModel.Interfaces;

namespace ViewModel
{
    public delegate void NewProjectCreatedEventHandler(object sender, IProjectCreatedEventArgs e);

    public class AddProjectViewModel : IAddProjectViewModel
    {
        public AddProjectViewModel(IViewModelObjectFactory factory, IProjectRepository repository)
        {
            _factory = factory;
            _CreateProjectCommand = factory.CreateCommand(CanCreateProject, CreateNewProject);
            _repository = repository;
        }

        private IViewModelObjectFactory _factory;
        private ICommand _CreateProjectCommand;

        public event NewProjectCreatedEventHandler NewProjectCreated;
        private IProjectRepository _repository;
        
        public string ProjectName { get; set; }

        public ICommand CreateProjectCommand
        {
            get { return _CreateProjectCommand; }
        }

        public void CreateNewProject()
        {
            _repository.CreateProject(ProjectName);
        }

        public bool CanCreateProject()
        {
            return !String.IsNullOrWhiteSpace(ProjectName);
        }
    }
}
